function maxProfit(prices: number[]): number {
  let minProfit: number = Number.MAX_SAFE_INTEGER;
  let maxProfit = 0;
  for (let i = 0; i < prices.length; i++) {
    if (prices[i] < minProfit) {
      minProfit = prices[i];
    } else {
      let profit = prices[i] - minProfit;
      maxProfit = Math.max(maxProfit, profit);
    }
  }
  return maxProfit;
}
console.log(maxProfit([7, 1, 5, 3, 6, 4]));
